# Maintainer: Johannes Löthberg <johannes@kyriasis.com>
# Maintainer: Eli Schwartz <eschwartz@archlinux.org>
# Contributor: Daniel Wallace <danielwallace at gtmanfred dot com>
# Contributor: Alfredo Palhares <masterkorp@masterkorp.net>

pkgname=hub
pkgver=2.14.2
pkgrel=3

pkgdesc="cli interface for Github"
url="https://hub.github.com"
arch=('loong64' 'x86_64')
license=('MIT')

depends=('git')
makedepends=('go')

source=("hub-$pkgver.tar.gz::https://github.com/github/hub/archive/v$pkgver.tar.gz"
        "fix-tests.patch::https://github.com/github/hub/commit/f1170f982c414ec53ebf35ad3b250226ec18a952.patch")
sha256sums=('e19e0fdfd1c69c401e1c24dd2d4ecf3fd9044aa4bd3f8d6fd942ed1b2b2ad21a'
            'fb0213f5bec7a64d9d0f02e7fbe6acb99fdfc3fee5ce0bdc5a57900c36d68f31')
b2sums=('b0ff7bcebca7f4b515acf412b756da8512dad7c89f1976cc749c68d70303ff7172b6817e92c839c1864b55ac137e67cf1c99fa07e09b01fd76ad3d40be8d2163'
        'fd54c571e0f41a42318c83341f1abd8cf7d0649a33f0a3399b9b5f6f72d1d37b0980bc4f0631b0f4031cdee95217b00693447006b1fc266d66311a552a85c79a')

prepare() {
    cd "${pkgname}-${pkgver}"
    patch -Np1 < "$srcdir/fix-tests.patch"
    cd $srcdir
    [ -d sys ] || git clone https://github.com/golang/sys.git
    [ -d net ] || git clone https://github.com/golang/net.git
}

build() {
  cd "$srcdir"/hub-$pkgver

  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-trimpath -mod=readonly -modcacherw"

  rm -rf vendor/golang.org/x/sys/
  rm -rf vendor/golang.org/x/net/
  cp -r $srcdir/sys vendor/golang.org/x/sys/
  cp -r $srcdir/net vendor/golang.org/x/net/

  make
  make man-pages
}

check() {
  cd "$srcdir"/hub-$pkgver

  make test
}

package() {
  cd "$srcdir"/hub-$pkgver

  make PREFIX="$pkgdir"/usr install

  install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
  install -Dm644 etc/hub.bash_completion.sh "$pkgdir"/usr/share/bash-completion/completions/hub
  install -Dm644 etc/hub.zsh_completion "$pkgdir"/usr/share/zsh/site-functions/_hub
  install -Dm644 etc/hub.fish_completion "$pkgdir"/usr/share/fish/vendor_completions.d/hub.fish
}
